﻿//-----------------------------------------------------------------------
// <copyright file="OracleAdapter.cs" company="NECSV">
//     Copyright (c) NECSV. All rights reserved.
// </copyright>
// <summary>Base class for all access to Oracel DB.</summary>
//-----------------------------------------------------------------------
namespace LMT.Db.OracleClient
{
    using System.Data.Common;
    using System.Data.OracleClient;

    /// <summary>
    /// Helper class for all access to Oracle database
    /// </summary>
    public sealed class OracleProvider : DbProvider
    {
        /// <summary>
        /// 
        /// </summary>
        private static OracleProvider oracleProvider;

        /// <summary>
        /// Gets the instance.
        /// </summary>
        public static OracleProvider Instance
        { 
            get
            {
                if (OracleProvider.oracleProvider == null)
                {
                    OracleProvider.oracleProvider = new OracleProvider();
                }

                return OracleProvider.oracleProvider;
            }
        }

        /// <summary>
        /// Prevents a default instance of the <see cref="OracleProvider"/> class from being created.
        /// </summary>
        private OracleProvider()
        {
        }

        /// <summary>
        /// Initializes the oracle environment.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <exception cref="System.Data.OleDb.OleDbException"></exception>
        ///   
        /// <exception cref="System.InvalidOperatorException"></exception>
        public override void InitializeEnvironment(string connection)
        {
            base.InitializeEnvironment(connection);
            this.EntityParser = OracleEntity.Instance;
        }

        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        protected override DbConnection CreateConnection(string connection)
        {
            return new OracleConnection(connection);
        }

        /// <summary>
        /// Creates the data adapter.
        /// </summary>
        /// <param name="oledbCom">The oledb COM.</param>
        /// <returns></returns>
        protected override DbDataAdapter CreateDataAdapter(DbCommand oledbCom)
        {
            return new OracleDataAdapter(oledbCom as OracleCommand);
        }
    }
}